package User;

import book.Book;
import book.Library;

import java.time.LocalDateTime;
import java.util.Locale;
import java.util.Scanner;

public class AdminUser extends User{
    public AdminUser(int ID, String name) {
        super(ID, name, "管理员");
    }

    @Override
    public int getID() {
        return super.getID();
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public String getRole() {
        return super.getRole();
    }

    Scanner scanner = new Scanner(System.in);
    @Override
    int mune() {
        System.out.println("管理员 " + getName() + " 的操作菜单:");
        System.out.println("1. 查找图书");
        System.out.println("2. 打印所有的图书");
        System.out.println("3. 退出系统");
        System.out.println("4. 上架图书");
        System.out.println("5. 修改图书");
        System.out.println("6. 下架图书");
        System.out.println("7. 统计借阅次数");
        System.out.println("8. 查看最后欢迎的前K本书");
        System.out.println("9. 查看库存状态");
        System.out.println("10. 检查超过⼀年未下架的图书");
        System.out.println("请选择你的操作：");
        return scanner.nextInt();
    }

    //上架图书
    public void addBook() {
        System.out.println("开始上架图书：");
        scanner.nextLine();
        System.out.println("请输入书名：");
        String title = scanner.nextLine();
        System.out.println("请输入作者：");
        String author = scanner.nextLine();
        System.out.println("请输入种类：");
        String category = scanner.nextLine();
        System.out.println("请输入出版年份：");
        int year = scanner.nextInt();
        scanner.nextLine();
        LocalDateTime shelfDate = LocalDateTime.now();
        Book newbook = new Book(title,author,category,year,shelfDate);
        Library.getInstance().addBook(newbook);
    }
    //图书修改 ⽀持修改书名 作者 类别
    public void updateBook() {
        Library.getInstance().displayBook();
        System.out.println("请选择要修改的书籍ID：");
        int booknumber = scanner.nextInt();
        Book book = Library.getInstance().searchBookID(booknumber);//将找到的书籍对象赋给book
        if(book == null) {
            System.out.println("没有查找到ID为" +booknumber+"的书籍");
            return;
        }
        System.out.println("当前书名为："+book.getTitle());
        scanner.nextLine();
        System.out.println("请输入新的书名：");
        String newTitle = scanner.nextLine();
        System.out.println("当前作者为："+book.getAuthor());
        System.out.println("请输入新的作者：");
        String newAuthor = scanner.nextLine();
        System.out.println("当前种类为："+book.getCategory());
        System.out.println("请输入新的种类：");
        String newCategory = scanner.nextLine();
        //利用set方法将书籍信息进行修改
        book.setAuthor(newAuthor);
        book.setCategory(newCategory);
        book.setTitle(newTitle);
        Library.getInstance().updateBook(book);
        System.out.println("图书更新完成！");
    }
    //删除书籍
    public void removeBook() {
        Library.getInstance().displayBook();
        System.out.println("选择你要下架书籍的ID");
        int booknumber = scanner.nextInt();
        scanner.nextLine();
        Book book = Library.getInstance().searchBookID(booknumber);
        Library.getInstance().removeBook(booknumber);
        System.out.println("图书"+book.getTitle()+"移除成功！");
    }
    //统计每本书的借阅次数
    public void borrowCount() {
        Library.getInstance().borrowCount();
    }
    //查询最受欢迎的前n本书
    public void mostlikeBook() {
        //需要对n的值进行合理性判断
        System.out.println("请输入想要查询的最受欢迎的前多少本书");
        int n = scanner.nextInt();
        if(n <= 0 || n>Library.getInstance().getBookCount()) {
            System.out.println("没有最受欢迎的前"+n+"本书！");
            return;
        }
        Library.getInstance().mostlikeBook(n);
    }
    //查看库存状态
    public void checkInventoryStatus() {
        Library.getInstance().checkInventoryStatus();
    }
    //移除上架超过⼀年的图书
    public void checkAndRemoveOldBook() {
        Library.getInstance().checkAndRemoveOldBook(scanner);
    }
}
